<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<textarea  style="width:100%;height:100%">
var ${ControllerName}Model = $.extend(TradeModel, {
    selRow: null, 
    editor:{
	    title: '${ControllerTitle}',
		winid:'${ControllerName}_EditForm',
		formid:'${ControllerName}_EditForm_fm',
		width:720,
		height:300
	},  
    postAction: 'add',
    url: '/${PACKAGE}/${ControllerName}',
    title: '${ControllerTitle}',
    idField: "${idField}",
    titleField: "${idField}",
    toolbar: '${ControllerName}_Toolbar',
    datagrid: '${ControllerName}_Grid' 
}); 
 
${ControllerName}Model.reload =function() {
	ReloadList_${ControllerName}();
	$('#${ControllerName}_EditForm').dialog('close'); 
} 


function Del_${ControllerName}() {
    var _checkedItems = $('#${ControllerName}_Grid').datagrid('getChecked');
    var _delcount=0;
    var _names = '';
    if(_checkedItems.length<1) {
        $.messager.alert('提示', '请选择需要删除的数据!' );
        return;
    }
    $.each(_checkedItems, function(index, item){
        _names +='<br/>'+ item[${ControllerName}Model.titleField] ;
    });
    var url = ${ControllerName}Model.url+'/del' ;
    $.messager.confirm('确定要删除如下信息?', '' + _names , function (r) {
        if (r) {
           var postdata={
                "reqBody": {} ,
                "reqHead": {
                    "sysCode": "contest18_test"
                }
            }
            $.each(_checkedItems, function(index, item){
                postdata.reqBody=item;
                Onluy.ajax.postData(url,postdata,  function(result){
                    if (result.rspCode ==0) {
                        _delcount++;
                    }
                },function(error){  } );
            });
            $.messager.alert('提示', '成功删除'+_delcount+'条数据!' );
            ReloadList_${ControllerName}();
        }
    });
}

function ShowEditForm_${ControllerName}(type) {
     switch (type) {
        case  1:
            var checkedItems = $('#${ControllerName}_Grid').datagrid('getChecked');
            if(checkedItems.length>1){
                $.messager.alert('提示', '只能选择一条记录修改!' );
                return;
            }
${ControllerName}Model.selRow = checkedItems[0];
${ControllerName}Model.postAction = 'update';
            break;

        case  0:
        default:
            ${ControllerName}Model.selRow = {}
            ${ControllerName}Model.postAction = 'add';
            break;
    }

    $('#${ControllerName}_EditForm_fm').form('clear' );
    $('#${ControllerName}_EditForm_fm').form('load', ${ControllerName}Model.selRow);
    $('#${ControllerName}_EditForm').dialog({
        resizable: false,
        maximizable: false
    })
    .dialog('open')
    .dialog('setTitle', (${ControllerName}Model.postAction == 'add') ? '新增' + ${ControllerName}Model.title : '修改' + ${ControllerName}Model.selRow[${ControllerName}Model.titleField]);
}

function save_${ControllerName}() {
    ${ControllerName}Model.submit();
}


function ${ControllerName}Searchbox(value, name) {
    if (value == "" || value == null) {
        $.messager.alert('提示', '请输入关键字!', 'info');
    }
    else {
        $('#${ControllerName}_Grid').datagrid('reload');
    }
}
 
function ReloadList_${ControllerName}() {
    $('#${ControllerName}_Grid').datagrid('reload');
}
 


$(function () {   
    $('#${ControllerName}_Grid').datagrid({
        pageSize: 10,
        fit: true,
        checkOnSelect: true,
        selectOnCheck: true,
        singleSelect: false,
        checkbox: true,
        fitColumns: true,
        pagination: true,
        method: 'post',
        url: ${ControllerName}Model.url+'/list',
        loader:${ControllerName}Model.Loader,
        toolbar: '#${ControllerName}_Toolbar', 
        columns: [
            [
                { field: 'ck',  checkbox: true },
    <#list  collist as  colum>
        <#if colum.COLUMN_COMMENT?length gt 0>
            { field: '${colum.COLUMN_NAME}', title: '${colum.COLUMN_COMMENT}', width:100, align: 'left',sortable:true },
        <#else>
            { field: '${colum.COLUMN_NAME}', title: '${ colum.COLUMN_NAME}', width:100, align: 'left',sortable:true },
        </#if>
    </#list>
			 {
					    field: 'opt', title: '自定义样式', width: 100, align: 'center',
					    formatter: function (value, rec) {
                            var htmlstr= rec['sysCode']+'<br/>';
					        return   htmlstr;
					    }
					}
            ]
        ],

        
        onLoadError: function (res) {
        	${ControllerName}Model.ShowException(res); 
        },
        onLoadSuccess: function (data) {
           if(data.success){ }
           else if(data.msg){
        		 $.messager.alert('加载错误', data.msg );
        	} 
        },
        onBeforeLoad: function (param) { 
        	$('#${ControllerName}_Grid').datagrid('clearSelections');
            param['catchKey'] = Math.random();
            param['name'] = $('#${ControllerName}_ss').searchbox('getName');
            param['value'] = $('#${ControllerName}_ss').searchbox('getValue');
        }
    });
    //设置分页控件  
    var p = $('#${ControllerName}_Grid').datagrid('getPager');
    $(p).pagination({
        pageSize: 10, //每页显示的记录条数，默认为10
        pageList: [10,20, 30, 50, 100], //可以设置每页记录条数的列表
        beforePageText: '第', //页数文本框前显示的汉字  
        afterPageText: '页    共 {pages} 页',
        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
        onBeforeRefresh: function () {
            $(this).pagination('loading');
            $(this).pagination('loaded');
        }
    });

});



</textarea>
</body>
</html>
 